#include "version.h"

#include "graph/ff_graph.h"

#ifdef MCSSTA
#include "../algorithm/mc_ssta.h"
#endif

#include "local/graph_partition.h"

#ifdef INTEGRATION
#include "local/graph_combine.h"
#endif

#ifdef REDUCTION
#include "cloud/graph_reduction.h"
#endif

int main(int argc, char * argv[]) 
{
    int phase = 2; // protect scheme 1,2,3

    vector<char*> benchs;

    //benchs.push_back(argv[1]);
    
    //unsigned MCNUM = atoi(argv[2]);

#ifdef ISCAS89
    benchs.push_back("s35932");
    benchs.push_back("s38417");
    benchs.push_back("s38584");
#else
    benchs.push_back("b17");
    benchs.push_back("b20");
    benchs.push_back("b21");
    benchs.push_back("b22");
    benchs.push_back("b18");
    benchs.push_back("b19");
#endif



    char ffc_file[50];
    char itc_file[50];
    char dag_file[50];
    char hgr_file[50];
    char delay_file[50];
    char delay_format_file[50];

    for (unsigned int i = 0; i < benchs.size(); i++)
    {
        strcpy(ffc_file, "../benchmark/BENCH/ffc/");
        strcat(ffc_file, benchs[i]);
        strcat(ffc_file, ".ffc");
        strcpy(dag_file, "../benchmark/BENCH/dag/");
        strcpy(delay_file, "../benchmark/BENCH/delay_pl/");
        strcpy(delay_format_file, "../benchmark/BENCH/delay_pl/");
        strcpy(hgr_file, "../benchmark/BENCH/partition/");
   
        strcat(dag_file, benchs[i]);
        strcat(dag_file, ".dag");

        strcat(delay_file, benchs[i]);
        strcat(delay_file, ".delay");

        strcat(delay_format_file, benchs[i]);
        strcat(delay_format_file, "_format.delay");

        strcat(hgr_file, benchs[i]);
        strcat(hgr_file, ".hgr");

        ff_graph ff_obj;

#ifdef MCSSTA
        strcpy(itc_file, "../benchmark/BENCH/ITC99/");
        strcat(itc_file, benchs[i]);
        strcat(itc_file, ".bench");

        //ff_obj.itc_to_dag(itc_file, dag_file);
        //ff_obj.ffc_to_dag(ffc_file, dag_file);
        //ff_obj.to_delay(delay_format_file);
        ff_obj.gen_graph(dag_file, delay_format_file);

        mc_ssta ssta_obj;
        ssta_obj.mc_ssta_pert(ff_obj, MCNUM, CLOCK);
#endif

        /*  
        * partition the graph: 
        *   output partitioned graph and delay for cloud;
        *   record colored vertex delay locally
        */
#ifdef EXTRACTION
        ff_obj.gen_graph(dag_file, delay_format_file);
        graph_partition gp_obj;

        //gp_obj.dag_to_hgr(ff_obj, hgr_file);
        //gp_obj.dag_to_reduce_hgr(ff_obj, hgr_file);
        gp_obj.ip_protection(ff_obj, benchs[i]);
#endif

#ifdef REDUCTION
        graph_reduction gr_obj;
        gr_obj.partial_mc_ssta(benchs[i], MCNUM, ff_obj);
#endif

#ifdef INTEGRATION
        graph_combine gc_obj;
        gc_obj.mc_ssta_reduce(benchs[i], MCNUM, ff_obj);
#endif

    }

    printf("Time = %.2lf\n", (double) clock()/CLOCKS_PER_SEC);
    return 1;
}